package com.gdk.ksoft.assembly.utils.system;

import android.content.Context;
import android.util.TypedValue;

/**
 * Created by Mrper on 2015/4/18.
 */
public class DensityUtils {

    public static float dp2px(Context context,float dp){
        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,dp,
                context.getResources().getDisplayMetrics());
    }

    public static float sp2px(Context context,float sp){
        return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,sp,
                context.getResources().getDisplayMetrics());
    }

    public static float px2dp(Context context,float px){
        float scale = context.getResources().getDisplayMetrics().density;
        return px/scale + 0.5f;
    }

    public static float px2sp(Context context,float px){
        float scale = context.getResources().getDisplayMetrics().scaledDensity;
        return px/scale;
    }

}
